defmodule Scrabble do
  @doc """
  Calculate the scrabble score for the word.
  """
  @spec score(String.t()) :: non_neg_integer
  def score(word) do
    word
    |> String.trim()
    |> String.downcase()
    #|> to_charlist
    |> String.split("")
    #|> Enum.map_reduce(0, &(&2 + score4letter(&1)))
    |> Enum.map(&score4letter/1)
    |> Enum.sum

  end

  def score4letter(""), do: 0
  def score4letter(<<c>>) do
    #IO.inspect IEx.Info.info(c)
    #IO.inspect IEx.Info.info('k')
    #IO.inspect IEx.Info.info(<<c>>)
    cond do
      c in 'aeioulnrst' -> 1
      c in 'dg'         -> 2
      c in 'bcmp'       -> 3
      c in 'fhvwy'      -> 4
      c in 'k'          -> 5
      c in 'jx'         -> 8
      c in 'qz'         -> 10
      true              -> 0
    end
  end

end
